<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\bootstrap\ActiveForm;
use yii\helpers\ArrayHelper;

$this->title = 'view';
?>
<style>
	.add_department .box-footer{text-align:center;border-top:0;}
	.add_department .box-footer button{width:200px;}
</style>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box-header"><h2 class="box-title">客户意向记录</div>
			<div class="box-body add_department">
				<?=Html::beginForm(Url::toRoute(['customer/view', 'uid' => $uid]), 'post', ['class'=>'form']);?>
					<div class="box-body">
						<div class="form-group">
							<label>客户姓名</label><br/>
							<?= $username ?>
						</div>
						<div class="form-group">
							<label>选择意向产品</label>
							<select name="pid" class="form-control intention_prod">
								<option>请选择产品</option>
								<?php foreach ($product as $val): ?> 
									<option value="<?= $val['id'] ?>"><?= $val['name']?></option>
								<?php endforeach;?>
							</select>
						</div>
						<div class="change-data">
							<div class="form-group">
								<label>认可度</label>
								<input type="hidden" name="_csrf" value="<?=Yii::$app->request->getCsrfToken() ?>">
								<input type="text" value="" name="agreed" class="form-control" />
							</div>
							<div class="form-group">
								<label>疑惑点</label>
								<textarea name="confusion" class="form-control"></textarea>
							</div>
							<div class="form-group">
								<label>考虑因素</label>
								<textarea name="consider" class="form-control"></textarea>
							</div>
				            <div class="form-group">
				              <label>备注信息</label>
								<textarea name="remark" class="form-control"></textarea>
				            </div>
			            </div>
					</div>
					<div class="box-footer">
						<button type="submit" class="btn btn-primary">确定</button>
					</div>
				<?=Html::endForm();?>
			</div>
		</div>
	</div>
</section>

<script src="js/jquery.js"></script>
<script>
	$(".intention_prod").change(function(){
		var pid = $(this).val();
		var uid = "<?= $uid ?>";
		var url = "<?= Url::toRoute('customer/getintention')?>";
		var _csrf ="<?= Yii::$app->request->getCsrfToken()?>";
		$.ajax({
			url:url,
			type:'GET',
			dataType:'json',
			data: {
				pid:pid,
				uid:uid,
				_csrf:_csrf
			},
			success: function(json){
				var html = "";
				if (json.flag) {
					html = "<div class='form-group'>"+
								"<label>认可度</label>"+
								"<input type='text' value='"+json.data.agreed+"' name='agreed' class='form-control' />"+
							"</div>"+
							"<div class='form-group'>"+
								"<label>疑惑点</label>"+
								"<textarea name='confusion' class='form-control'>"+json.data.confusion+"</textarea>"+
							"</div>"+
							"<div class='form-group'>"+
								"<label>考虑因素</label>"+
								"<textarea name='consider' class='form-control'>"+json.data.consider+"</textarea>"+
							"</div>"+
				            "<div class='form-group'>"+
				             	"<label>备注信息</label>"+
								"<textarea name='remark' class='form-control'>"+json.data.remark+"</textarea>"+
				            "</div>";
				    $(".change-data").html(html);
				} else {
					html = "<div class='form-group'>"+
								"<label>认可度</label>"+
								"<input type='text' value='' name='agreed' class='form-control' />"+
							"</div>"+
							"<div class='form-group'>"+
								"<label>疑惑点</label>"+
								"<textarea name='confusion' class='form-control'></textarea>"+
							"</div>"+
							"<div class='form-group'>"+
								"<label>考虑因素</label>"+
								"<textarea name='consider' class='form-control'></textarea>"+
							"</div>"+
				            "<div class='form-group'>"+
				             	"<label>备注信息</label>"+
								"<textarea name='remark' class='form-control'></textarea>"+
				            "</div>";
					$(".change-data").html(html);
				}
			},
			error:function(){
			  alert('网络忙');
			}
		});
	});
</script>